
    var block   = '';
    var post_id = null;
    function buildurl() {
        var cate_id= $("#classid option:selected").val();
        var statusid= $("#statusid option:selected").val();
        $.ajax({
            url : user_ajax + "/url",
            data: {'status':statusid,'cate_id':cate_id},
            type: "POST",
            dataType:"json",
            success:function(re) {
                if(re.code =='ok') {
                    var str  = '';
                    $.each(re.data,function(k,v){
                       str  += html_str(k, v);
                    });
                    //var str = $("#list_first").html();
                    $(".list_tr").remove();
                    $("#list_url").append(str);
                      tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
                      imgLoader = new Image();// preload image
                      imgLoader.src = tb_pathToImage;
                }else{
                    $(".list_tr").remove();
                }
            }
        });

    }

    function html_str(k,v) {
        var str = '';
            str +='<tr class="list_tr">';
            str +='    <td><input type="checkbox" value="'+v.id+'" name="ids"></td>';
            str +='     <td>'+v.total_pv+'</td>';
            str +='    <td>'+v.url+'</td>';
            str +='    <td><a href="http://u22.cc/'+v.uhash+'+">'+v.uhash+'+</a></td>';
            str +='    <td>'+v.add_time+'</td>';
            str +='    <td>';
            str +='        <span onmouseover="over(this)" class="more"><a href="#">更多</a>';
            str +='        <div style="display: none;" class="more_event">';
            str +='                <ul>';
            str +='                    <li><a class="thickbox" title="编辑" href="'+user+'/ajax_edit/id/'+v.id+'">编辑</a></li>';
            str +='                    <li><a class="thickbox" title="复制短网址" href="'+user+'/copy_url/id/'+v.id+'">复制</a> </li>';
            str +='                    <li><a href="'+user+'/over_view/id/'+v.id+'">概要统计</a></li>';
            str +='                    <li><a href="'+user+'/show/uhash/'+v.uhash+'/id/'+v.id+'">详细统计</a></li>';
            str +='                </ul>';
            str +='           </div>';
            str +='        </span>';
            str +='    </td>';
            str +='</tr>';
            return str;
    }
    
    function check_all_url(chk){
        if(chk.checked){
            $(".list").find("[name='ids']").each(function(){this.checked = true;});
        } else {
            $(".list").find("[name='ids']").each(function(){this.checked = false;});
        }
    }

    function move_to(t) {
        var urls=$("input[name=ids]:checked");
        var urlids = Array();
        for(i=0;i<urls.length;i++){
            urlids[i]=urls[i].value;
           
        }
        
        if(urlids.length>0){
            post_id = urlids;
            var moveurlto= $("#moveurlto option:selected").val();
            //新建分类
            if(moveurlto == -2) {
 
                cate_add_show();
            }else{
                if(moveurlto == 0) {
                    return ;
                }
                var new_cate    = $("#new_cate option:selected").val();
                //切换分类
                change_cate(urlids,new_cate);
            }
        }else{
            alert('请选择分类')
        }
    }

    //网址分类
    function init_cate(){
        $.ajax({
            url : user_ajax+"/cate/",
            dataType:"json",
            success:function(re) {
                var str = '';
                str +='<option value="">全部短网址</option>';
                str +='<option value="-1">回收站</option>';
                str +='<option value="-999">未分类</option>';
                if(re.code == 'ok') {
                    var s    = '';
                    $.each(re.data,function(k,v){
                        s += '<option value="'+v.id+'">'+v.title+'</option>';
                    });
                    $("#new_cate").html('<option value="-1">移到回收站</option>'+s);
                    $("#classid").html(str+s);
                }else{
                     $("#classid").html(str);
                }
            },beforeSend:function(){
                //$("#loader_container").show();
                //$("#loader_container_msg").html('加载中...');
            }

        });
    }

    function init_url() {
       $.ajax({
            url : user_ajax+"/url/",
            dataType:"json",
            success:function(re) {
                if(re.code == 'ok') {
                    var str = '';
                }
            },beforeSend:function(){
                //$("#loader_container").show();
                //$("#loader_container_msg").html('加载中...');
            }

        });
    }

    function over(obj){
        
        var width   = $(window).width()+17;
        var left    = (width - 958) / 2 ;
        var ls      = width - left - ($(obj).width() * 2);
        var s   = $(obj).offset().top;
        //alert(s);
        $(obj).find(".more_event").attr('style', 'left:'+ls+'px;top:'+s+'px');
        $(obj).mouseout(function(){$(obj).find(".more_event").css("display","none")});
    }

    function on_mouse_over(obj) {
        //alert($(obj).html());
        var width   = $(window).width()+17;
        var left    = (width - 958) / 2 ;
        var ls      = width - left - ($(obj).width() * 2);
        var s   = $(obj).offset().top + 20;
        //alert(s);
        $(".more_event").attr('style', 'left:'+ls+'px;top:'+s+'px');
    }

    //显示添加分类页面
    function cate_add_show() {

        var wd  = $("#new_cates");
        var width   = $(window).width();
        var left    =  (width - wd.width()) /2;
        var top     = $(".history").css('top');
        var mid     = ($(window).height() - wd.height()) /2 - 100 ;
        wd.css({"left":left+"px","top":mid+"px;"});
        $("#new_cates").show();
    }

    function hide_cate() {
        $('#new_cates').hide();
    }
    
    function cate_add_ajax(){
        var title   = $("#textfield_ss").val();
        $.ajax({
            url: user_ajax+"/cate_add/",
            data:{'title':title,'ids':post_id},
            dataType: "json",
            type: "POST",
            success:function(re){
                if(re.code == 'ok') {
                    if(re.is_new == true) {
                        $("#classid").append('<option value="'+re.data.id+'">'+re.data.title+'</option>');
                        $("#new_cate").append('<option value="'+re.data.id+'">'+re.data.title+'</option>');
                    }
                    $(".list_tr").remove();
                }else{
                    alert(re.data)
                }
                $("#new_cates").hide();
                $("#loader_container").hide();
            },beforeSend:function(){
                $("#loader_container").show();
                $("#loader_container_msg").html('分类添加中...');
            }
        });
    }

    //切换分类
    function change_cate(urlids,cate_id) {
        $.ajax({
            url: user_ajax+"/set_cate",
            data:{'ids' :urlids,'cate_id':cate_id},
            type: "POST",
            success:function(re){
                if(re == 'ok') {
                    $("#loader_container").show();
                    $("#loader_container_msg").html('移动成功');
                    //$(".list_tr").remove();
                    $("input[name=ids]:checked").parent().parent().remove();
                    $("#loader_container").hide();
     
                }
            }
        });
    }

    function page_center(obj) {
        block   = obj;
        var width   = $(window).width();
        var obj_width   = $("."+obj).width();
        var left = (width - obj_width) /2;

        var height   = $(window).width();
        var obj_height   = $("."+obj).height();

        var mid = (height - obj_height) /2;
        $("."+obj).css('style', 'left:'+width+'px;top:'+mid+'px;');
    }

    function setprivacy(val) {
        if (val == 0) {
            alert('请选择');
            return ;
        }
        var urls=$("input[name=ids]:checked");
        var urlids = Array();
        for(i=0;i<urls.length;i++){
            urlids[i]=urls[i].value;
        }
        $.ajax({
            url: user_ajax+"/set_status",
            data:{'ids' :urlids,'status':val},
            type: "POST",
            success:function(re){
                alert('修改成功');
            }
        });
    }

    function showDiv(ele,id) {
        $("#"+eld).show();
    }
